<?php

namespace catchAdmin\pc\model;

use catchAdmin\model\Notice;
use catcher\exceptions\AlertErrorException;

class ZhaoPin extends \catchAdmin\model\ZhaoPin
{

    public $name = '';


    /**
     * 审核
     */
    public function audit($param)
    {
        $msg = $this
            ->where('id', $param['id'])
            ->where('audit_status', 1)
            ->find();

        if (empty($msg)) {
            throw new AlertErrorException('不能重复审核');
        }

        $this->startTrans();

        // 1.保存审核状态
        $msg->audit_status = $param['audit_status'];
        $msg->audit_note = $param['audit_note'];
        $msg->audit_time = time();
        $msg->save();

        // 2.发消息
        (new Notice())->saveDataCC([
            // 提现审核——审核结果
            'notice_type'    => 5,
            'title'          => $msg['audit_status_name'],
            'content'        => $msg['audit_note'],
            'wechat_user_id' => $msg['wechat_user_id'],
        ]);

        $this->commit();

        return true;
    }


    public function indexData($param)
    {
        $app = $this->with(['wechatUser']);

        return $this->indexDataPcCC($param, $app);
    }
}
